import java.util.*;

public class Test14_2 {
    public static void main(String[] args) {
        ArrayList<Integer> list = new ArrayList<>();
        list.add(1);
        list.add(2);
        list.add(3);
        list.add(4);
        list.add(5);

        //fori
        for (int i = 0; i < list.size(); i++) {
            System.out.print(list.get(i) + " ");
        }
        System.out.println();

        //foreach
        for (Integer integer:list) {
            System.out.print(integer+" ");
        }
        System.out.println();

        //迭代器
        Iterator<Integer> it = list.iterator();
        while (it.hasNext()) {
            System.out.print(it.next() + " ");
        }
        System.out.println();

        ListIterator<Integer> listIterator = list.listIterator();
        while (listIterator.hasNext()) {
            System.out.print(listIterator.next() + " ");
        }
        System.out.println();

        //从后往前遍历                                             传起始位置
        ListIterator<Integer> listIterator1 = list.listIterator(list.size());
        while (listIterator1.hasPrevious()) {
            System.out.print(listIterator1.previous() + " ");
        }
        System.out.println();
    }
    public static void main2(String[] args) {
        ArrayList<Integer> list= new ArrayList<>();
        List<Integer> list1 = new ArrayList<>();
        list1.add(1);
        List<Integer> list2 = new LinkedList<>();
        list2.add(0);
        list2.add(1);
        List<Integer> list3 = new ArrayList<>(list2);
        //List<String> list4 = new ArrayList<>(list1); 错
        list3.add(2);
        System.out.println(list1);
        System.out.println(list2);
        System.out.println(list3);

    }

    public static void main1(String[] args) {
        MyArrayList myArrayList = new MyArrayList();
        myArrayList.add(1);
        myArrayList.add(2);
        myArrayList.add(3);
        myArrayList.add(4);
        myArrayList.add(5);
        myArrayList.display();
        myArrayList.add(0,199);
        myArrayList.display();
        System.out.println(myArrayList.contains(1));
        System.out.println(myArrayList.indexOf(2));
        System.out.println(myArrayList.get(0));
        myArrayList.display();
        myArrayList.set(0,888);
        myArrayList.display();
        System.out.println(myArrayList.get(0));
        myArrayList.remove(888);
        myArrayList.remove(3);
        myArrayList.remove(5);
        myArrayList.display();
        myArrayList.remove(90);
    }
}
